package com.pirestupppai.widgets.view;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.RelativeLayout;

import com.pirestupppai.R;

/**
 * 带空视图的recyclerview
 *
 * author: xiaoluo
 * date: 2017/6/27 15:41
 */
public class CustomRecyclerView extends RelativeLayout{
    private Context mContext;
    private RecyclerView mRecyclerView;
    private EmptyView mEmptyView;

    public CustomRecyclerView(Context context) {
        this(context, null);
    }

    public CustomRecyclerView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CustomRecyclerView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;
        LayoutInflater.from(mContext).inflate(R.layout.widget_custom_recyclerview, this, true);
        mRecyclerView = (RecyclerView) findViewById(R.id.custom_recyclerview);
        mEmptyView = (EmptyView) findViewById(R.id.custom_empty_view);
    }

    /**
     * 空列表
     */
    public void setEmpty() {
        mRecyclerView.setVisibility(GONE);
        mEmptyView.setVisibility(VISIBLE);
    }

    public void noEmpty() {
        mRecyclerView.setVisibility(VISIBLE);
        mEmptyView.setVisibility(GONE);
    }

    public RecyclerView getRecyclerView() {
        return mRecyclerView;
    }

    public void setEmptyText(String text) {
        mEmptyView.setText(text);
    }
}
